package com.wps.netConnection.rpc
{
	import __AS3__.vec.Vector;

	/**
	 * rpcToken池
	 * @author zhuohongtao
	 */
	internal class RpcTokenPool
	{
		private var _tokens: Vector.<RpcToken> = new Vector.<RpcToken>();
		private var _connections: Vector.<Object> = new Vector.<Object>();

		public function RpcTokenPool()
		{
		}
		
		public function getToken(index: int): RpcToken
		{
			return _tokens[index];
		}

		public function addToken(token: RpcToken): void
		{
			_tokens.push(token);
			_connections.push(token.connection.connection);
		}

		public function removeToken(token: RpcToken): void
		{
			removeAt(_tokens.indexOf(token));
		}

		public function removeAt(index: int): void
		{
			if (index != -1)
			{
				_tokens.splice(index, 1);
				_connections.splice(index, 1);
			}
		}

		public function getTokenIndexByConnection(connection: Object): int
		{
			return _connections.indexOf(connection);
		}
	}
}
